package com.example.littleken.mytao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.littleken.mytao.R;
import com.example.littleken.mytao.entity.Menu;

import java.util.List;

/**
 * Created by littleken on 2018/4/17.
 */
//适配器定义真的恶心，都不知道自己在干什么
public class MainMenuAdapter extends RecyclerView.Adapter<MainMenuViewHolder>{
    protected  Context context;
    protected  List<Menu> menus;
    public  MainMenuAdapter(Context context, List<Menu>menus){
        this.context = context;
        this.menus = menus;
    }
    @Override
    public MainMenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MainMenuViewHolder(LayoutInflater.from(context).inflate(R.layout.item_main_menu,null));
    }

    @Override
    public void onBindViewHolder(MainMenuViewHolder holder, int position) {
        Menu menu = menus.get(position);
        holder.mImageMenuIcon.setImageResource(menu.icon);
        holder.mTextMenuName.setText(menu.menuName);
    }

    @Override
    public int getItemCount() {
        return null!=menus?menus.size():0;
    }
}

class  MainMenuViewHolder extends RecyclerView.ViewHolder{

    public ImageView mImageMenuIcon;
    public TextView mTextMenuName;
    public MainMenuViewHolder(View itemView) {
        super(itemView);
        mImageMenuIcon = (ImageView) itemView.findViewById(R.id.img_menu_icon);
        mTextMenuName = (TextView) itemView.findViewById(R.id.text_menu_name);

    }
}
